<template>
  <div id="body">
    <div id="saizhi"> 
      <div class="htitle">
        <strong>球员库</strong>
        
      </div>
    </div>
    <div style="margin: 10px 0">
      <el-input style="width: 200px;margin-right: 10px;" placeholder="请输入球员姓名" suffix-icon="el-icon-search" v-model="playerName"></el-input>

      <div>
      <el-input style="width: 200px;margin-right: 10px;" placeholder="请输入最小身价" suffix-icon="el-icon-search" v-model="playerMinValue"></el-input>

      <el-input style="width: 200px;margin-right: 10px;" placeholder="请输入最大身价" suffix-icon="el-icon-search" v-model="playerMaxValue"></el-input>
      
      <el-input style="width: 200px;margin-right: 10px;" placeholder="请输入球员身价" suffix-icon="el-icon-search" v-model="playerValue"></el-input>
      </div>

      <el-select v-model="leagueId" clearable placeholder="请选择联赛" style="width: 200px;margin-right: 10px;" @change="changeLeague()">
        <el-option v-for="item in leagueoptions" :key="item.id" :label="item.leagueName" :value="item.id">
            {{ item.leagueSeason+item.leagueName }}
        </el-option>
      </el-select>

      <el-select v-model="teamId" clearable placeholder="请选择球队" style="width: 200px;margin-right: 10px;">
        <el-option v-for="item in teamoptions" :key="item.id" :label="item.teamName" :value="item.id">
            {{ item.teamName}}
        </el-option>
      </el-select>

      <el-select v-model="playerPosition" clearable placeholder="请选择场上位置" style="width: 200px;margin-right: 10px;">
        <el-option v-for="item in positionoptions" :key="item.name" :label="item.name" :value="item.value">
            {{ item.name}}
        </el-option>
      </el-select> 

      <el-button class="ml-5" icon="el-icon-search" circle @click="load">查询球员</el-button>
      <el-button icon="el-icon-remove" circle @click="reset">重置查询</el-button>
    </div>

    <el-table
        :data="tableData"
        border
        stripe
        :header-cell-class-name="'headerBg'"
        @selection-change="handleSelectionChange"
        :default-sort = "{prop: 'playerAbility.capability', order: 'descending'}"
        @row-click="PlayerDetails"
      >
        ​​​​​​​<el-table-column
          prop="playerNumber"
          label="号码"
       sortable ></el-table-column>
        <el-table-column label="姓名">
          <template slot-scope="scope">
            <a class="testA" target="_blank" @click="PlayerDetail(scope.row.id)">
              {{ scope.row.playerName }}
            </a>
          </template>
        </el-table-column>
        <el-table-column prop="playerAge" label="年龄" sortable></el-table-column>
        <el-table-column  prop="playerHeight" label="身高(年龄)" sortable></el-table-column>
        <el-table-column prop="playerWeight"  label="体重(kg)" sortable></el-table-column>
        <el-table-column prop="playerPosition" label="位置"></el-table-column>
        <el-table-column prop="playerNation" label="国籍"></el-table-column>
        <el-table-column prop="playerValue" label="身价(万欧元)" sortable>
        </el-table-column>
        <el-table-column prop="playerAbility.capability" label="能力" sortable></el-table-column>
        <el-table-column  label="球队" >
          <template slot-scope="scope" v-if="scope.row.team">
            <a class="testA" target="_blank" @click="TeamDetail(scope.row.team.id)">
              {{ scope.row.team.teamName }}
            </a>
          </template>
        </el-table-column>
        <el-table-column prop="playerData.gamesPlayed" label="出场" sortable></el-table-column>
        <el-table-column prop="playerData.totalGoal" label="进球" sortable></el-table-column>
        <el-table-column prop="playerData.totalAssist" label="助攻" sortable></el-table-column>

      </el-table>
      <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="current"
          :page-sizes="[10, 20]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>

</template>

<script>
export default {
  name:"Player",
  data(){
    return{
      tableData:[],//球员列表
      playerName:"",//球员姓名搜索
      teamId:"",//球员所属球队id搜索
      teamoptions:[],//球队列表
      playerPosition:"",//球员场上位置搜索
      positionoptions:[],//位置列表
      playerValue:"",//球员身价搜索
      playerMaxValue:"",//球员最高身价搜索
      playerMinValue:"",//球员最低身价搜索
      leagueoptions:[],//联赛列表
      leagueId:"",//联赛搜索
      total:0,//总数
      current:1,//当前页
      size:11,//每页数量
    }
  },
  created(){
    this.load()
  },
  methods:{
    load(){
      this.request.get("/player/front/playerList",{
        params:{
          current:this.current,
          limit:this.size,
          playerName:this.playerName,
          playerPosition:this.playerPosition,
          teamId:this.teamId,
          playerValue:this.playerValue,
          playerMaxValue:this.playerMaxValue,
          playerMinValue:this.playerMinValue,
          
        }
      }).then(res=>{
        console.log(res.data)
        this.tableData=res.pagePlayer.records
        this.total=res.total
      }),
      //查询位置数据
      this.request.get("/player/position").then(res =>{
        console.log(res)
        this.positionoptions = res.data
      }),
      //查询所有球队信息到选择框中
      this.request.get("/team/findall").then(res =>{
        console.log(res.data)
        this.teamoptions = res.data
      }),
      //查询所有联赛信息到选择框中
      this.request.get("/league/findall").then(res=>{
        console.log(res.data)
        this.leagueoptions = res.data
      })
    },
     //选择联赛时，查询该联赛的轮次和球队
     changeLeague(){
      this.request.get("/league/findTeamByLeagueId/"+this.leagueId).then(res=>{
        if(res.code === '200'){
          this.teamoptions = []
          this.teamoptions = res.data
        }else{
          this.$message.error("查找失败")
        }
      })
    }, 
     handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    //分页每页大小
    handleSizeChange(size) {
      console.log(size)
      this.size = size
      this.load()
    },

    //分页第几页
    handleCurrentChange(current) {
      console.log(current)
      this.current = current
      this.load()
    },
    reset() {
      this.playerName = ""
      this.teamId = ""
      this.playerMaxValue=""
      this.playerMinValue=""
      this.playerValue=""
      this.playerPosition=""
      this.leagueId=""
      this.load()
    },
    PlayerDetail(id) {
       this.$router.push({
          path: '/front/playerdetail',
          query: {
            id: id
          }
        })
    },
    TeamDetail(id) {
       this.$router.push({
          path: '/front/teamdetail',
          query: {
            id: id
          }
        })
    },
    PlayerDetails(row,event,column){
      console.log(row, event, column)
      console.log(row.id)
      this.$router.push({
          path: '/front/playerdetail',
          query: {
            id: row.id
          }
        })
    },
  }
}
</script>

<style>
#saizhi{
  border: 1px solid #e5e5e5;
    margin-top: 8px;
    clear: both;
}
.htitle {
  line-height: 35px;
  text-align: center;
  font-size: 14px;
  background-color: #f0f0f0;
  position: relative;
}
.testA{
  color: #005eb8;
}
.testA:hover{
  cursor: pointer;
}
</style>